package com.qianbao.qianbaobusiness.ui.mine.settlementinfo;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.baseandroid.mvp.BaseMvpActivity;
import com.qianbao.qianbaobusiness.R;
import com.qianbao.qianbaobusiness.json.SettlementInfoBean;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author: Routee
 * @date 2018/6/20
 * @mail wangc4@qianbaocard.com
 * ------------1.本类由Routee开发,阅读、修改时请勿随意修改代码排版格式后提交到git。
 * ------------2.阅读本类时，发现不合理请及时指正.
 * ------------3.如需在本类内部进行修改,请先联系Routee,若未经同意修改此类后造成损失本人概不负责。
 */
public class SettlementInfoActivity extends BaseMvpActivity<SettlementInfoView, SettlementInfoPresenter> implements SettlementInfoView, SwipeRefreshLayout.OnRefreshListener {

    @BindView(R.id.tv_title)
    TextView           mTvTitle;
    @BindView(R.id.ll_empty)
    LinearLayout       mLlEmpty;
    @BindView(R.id.rv)
    RecyclerView       mRv;
    @BindView(R.id.srl)
    SwipeRefreshLayout mSrl;
    private SettlementInfoRvAdapter mRvAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_settlement_info;
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected void setupView() {
        mTvTitle.setText("结算信息");
        mRv.setLayoutManager(new LinearLayoutManager(this));
        mSrl.setColorSchemeColors(ContextCompat.getColor(this, R.color.text_red));
        mSrl.setOnRefreshListener(this);
        if (mRvAdapter == null) {
            mRvAdapter = new SettlementInfoRvAdapter(this);
        }
        mRv.setAdapter(mRvAdapter);
        netSettlementInfos();
    }

    private void netSettlementInfos() {
        getPresenter().getsettlementList();
    }

    @Override
    protected void setupData(Bundle savedInstanceState) {

    }

    @OnClick(R.id.iv_back_toolbar)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void onRefresh() {
        netSettlementInfos();
    }

    @Override
    public void getSettlementListSuccess(SettlementInfoBean result) {
        if (mSrl.isRefreshing()) {
            mSrl.setRefreshing(false);
        }
        if (result.getItems().size() != 0) {
            mLlEmpty.setVisibility(View.GONE);
        } else {
            mLlEmpty.setVisibility(View.VISIBLE);
        }
        mRvAdapter.resetData(result.getItems());
    }

    @Override
    public void onNetError() {
        if (mSrl.isRefreshing()) {
            mSrl.setRefreshing(false);
        }
    }
}
